$(document).ajaxComplete(
		function(event, xhr, settings) {
			if (xhr.getResponseHeader("sessionstatus") == "timeOut") {
				if (xhr.getResponseHeader("loginPath")) {
					alert("会话过期，请重新登陆!");
					if(window !=top){  
						top.location.replace(xhr
								.getResponseHeader("loginPath")); 
					}
					else {
						window.location.replace(xhr
								.getResponseHeader("loginPath"));
					}
					
				} else {
					alert("请求超时请重新登陆 !");
				}
			}
		});

/**
 * 自定义replaceAll contains startsWith endsWith等函数, 使用：元素.function
 */
$(function() {
	// replaceAll
	String.prototype.replaceAll = function(s1,s2){
		return this.replace(new RegExp(s1,"gm"),s2);
	};
	// contains
	Array.prototype.contains = function ( needle ) {
		  for (i in this) {
		    if (this[i] == needle) return true;
		  }
		  return false;
	};
	// startsWith
	if (typeof String.prototype.startWith != 'function') {
		  String.prototype.startWith = function (prefix){
		    return this.slice(0, prefix.length) === prefix;
		  };
	}
	// endWith
	if (typeof String.prototype.endWith != 'function') {
		   String.prototype.endWith = function(suffix) {
		     return this.indexOf(suffix, this.length - suffix.length) !== -1;
		   };
	}
});
/**
 * 等待完成后调用回调函数
 * 
 * @param waitime
 * @param callback
 * @returns
 */
function waitCompleted(waitime,callback){
　　　　setTimeout(function () {
　　　　　　// f1的任务代码
　　　　　　callback();
　　　　}, waitime);
}
/**
 * 公共弹窗信息
 * 
 * @param type
 * @param msg
 * @param timeout
 * @returns
 */
function dialog (type,msg,timeout) {	
  	var tipHtml = '';
	if (type =='loading'){
		tipHtml = '<img alt="" src="img/msgbox_loading.gif">'+(msg ? msg : '正在提交您的请求，请稍候...');
	} else if (type =='notice'){
		tipHtml = '<span class="gtl_ico_hits"></span>'+msg;
	} else if (type =='error'){
		tipHtml = '<span class="gtl_ico_fail"></span>'+msg;
	} else if (type =='succ'){
		tipHtml = '<span class="gtl_ico_succ"></span>'+msg;
	}
	if ($('.msgbox_layer_wrap')) {
		$('.msgbox_layer_wrap').remove();
	}
	if (st){
		clearTimeout(st);
	}
	$("body").prepend("<div class='msgbox_layer_wrap'><span id='mode_tips_v2' style='z-index: 10000;' class='msgbox_layer'><span class='gtl_ico_clear'></span>"+tipHtml+"<span class='gtl_end'></span></span></div>");
	$(".msgbox_layer_wrap").show();
	var st;
	if (timeout != '') {
		st = setTimeout(function (){
			$(".msgbox_layer_wrap").hide();
			clearTimeout(st);
		},timeout);
	}
}
/**
 * 验证字符串是否为空
 * 
 * @param string
 * @returns
 */
function isStrEmpt (string) {
	if (string=="" || string==null) {
		return true;
	}
	else if (string == "undefined" || typeof(string) == "undefined"){
		return true;
	}
	else {
		return false;
	}
}
/**
 * 验证字符串是否包含子串
 * 
 * @param str
 * @param substr
 * @returns
 */
function isContains(str, substr) {
    return new RegExp(substr).test(str);
}
/**
 * Js根据xpath获取元素
 * 
 * @param STR_XPATH
 * @returns
 */
function _x(STR_XPATH) {
    var xresult = document.evaluate(STR_XPATH, document, null, XPathResult.ANY_TYPE, null);
    var xnodes = [];
    var xres;
    while (xres = xresult.iterateNext()) {
        xnodes.push(xres);
    }
 
    return xnodes;
}
/**
 * simpletimepicker展示时间
 * 
 * @param element
 *            要展示的元素
 * @param format
 *            时间格式
 * @returns
 */
function simpletimepicker(element,format) {
	element.datetimepicker({
		  language: 'zh-CN',// 显示中文
		  format: format,// 显示格式
		  initialDate: new Date(),// 初始化当前日期
		  minView: 0,
		  minuteStep:1,
		  forceParse: false,
		  clearBtn:true,// 清除按钮
		  autoclose: true,// 选中自动关闭
		  todayBtn: true// 显示今日按钮
		 })
}
/**
 * simpletimepicker展示时间 （针对自定义时间格式需要转换为simpletimepicker时间格式的）
 * 
 * @param element
 * @param format
 * @returns
 */
function setTimePicker(element,format) {
	format = format.replaceAll("m", "i").replaceAll("M", "m");
	if (isContains(format,"h")) {
		format = format.replaceAll("h", "H");
	}
	else if (isContains(format,"H")) {
		format = format.replaceAll("H", "h");
	}
	element.datetimepicker('remove');
	simpletimepicker(element,format);
	return format;
}
/**
 * hbase设置页面中设置simpletimepicker
 * 
 * @returns
 */
function settimeInternalpicker() {
	setTimePicker($('#Hbase_starttime'),$('#Hbase_starttime').attr("name"));
	setTimePicker($('#Hbase_endtime'),$('#Hbase_endtime').attr("name"));
	setTimePicker($('#Hbase_exacttime'),$('#Hbase_exacttime').attr("name"));
}
/**
 * 删除全部勾选
 * 
 * @param table
 * @returns
 */
function delSelected(table) {
	var selects = table.children('tbody').children('tr').find('td:first > input');
	selects.each(function() {
		if (this.checked == true) {
			$(this).closest('tr').remove();
		}		
	});
}
/**
 * 全部选中
 * 
 * @returns
 */
function selectAll() {
	$(".checkAll").click(function() {
		var check = $(this).closest('table').children('tbody').children('tr').find('td:first > input');
		if (this.checked == true) {
			check.each(function() {
				this.checked = true;
			});
		} else {
			check.each(function() {
				this.checked = false;
			});
		}
	});
}
/**
 * 转换为datatable的公共方法
 * 
 * @param dt
 * @param ajax
 * @param aoColumnDefs
 * @param columns
 * @param initCompletefunc
 * @param searching
 * @returns
 */
function convertDataTable_common (dt,ajax,aoColumnDefs,columns,initCompletefunc,searching) {
	return dt.DataTable({
		 "dom": "<'row'<'col-md-6'l<'#toolbar'>><'col-md-6'f>r>" +
	        "t" +
	        "<'row'<'col-md-5 sm-center'i><'col-md-7 text-right sm-center'p>>",
       // 去掉查询框
       searching: searching,
       "bAutoWidth":false,
// //解决重新加载表格内容问题
       destroy:true,
       'bPaginate': true,
       "bSort": true,
       "bProcessing": true,
       "bStateSave": true,
       /* "serverSide": true, */
       "ajax": ajax,
	"aoColumnDefs": aoColumnDefs,
       "columns": columns,
       initComplete:initCompletefunc,
       // "aaSorting": [[1, 'asc']],//排序
       "aLengthMenu": [[10, 20, 50, 100, -1], ['10', '20', '50','100', "所有"] // change
																				// per
																				// page
																				// values
																				// here
       ],
       "iDisplayLength": 10,
       "oLanguage": {
           "oAria": {
               "sSortAscending": " - click/return to sort ascending",
               "sSortDescending": " - click/return to sort descending"
           },
           "sProcessing": "玩命加载中...",
           "sLengthMenu": "显示 _MENU_ 记录",
           "sZeroRecords": "对不起，查询不到任何相关数据",
           "sEmptyTable": "未有相关数据",
           "sLoadingRecords": "正在加载数据-请等待...",
           "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录。",
           "sInfoEmpty": "当前显示0到0条，共0条记录",
           "sInfoFiltered": "（数据库中共为 _MAX_ 条记录）",
           "sSearch": "模糊查询：",
           "sUrl": "",
           // 多语言配置文件，可将oLanguage的设置放在一个txt文件中，例：Javascript/datatable/dtCH.txt
           "oPaginate": {
               "sFirst": "首页",
               "sPrevious": " 上一页 ",
               "sNext": " 下一页 ",
               "sLast": " 尾页 "
           }
       },
       // 多语言配置

	});
}
var dragele;
function allowDrop(ev) {
	ev.preventDefault();
	
}
function drag(ev) {
	ev.dataTransfer.setData("ID", ev.target.id);
	dragele = $(ev.target);
}	

/**
 * 展示提示信息
 * 
 * @param element
 *            双击的元素
 * @param infoele
 *            提示信息元素
 * @param table
 *            展示信息的表
 * @param validata
 *            回调函数
 * @returns
 */
function ShowElement(element,infoele,table,validata)
{
	if ($(element).find('textarea').length == 0) {
		infoele.hide();
		$(element).unbind('mouseenter').unbind('mouseleave');
		$(element).removeClass('not_Empty_td');
		var oldhtml = $.trim($(element).text());
		var index = $(element).index();
		var thele = $(element).parent().parent().prev().find('th').eq(index);
		var newdiv = document.createElement('div');
		$(newdiv).addClass('form-group has-feedback has-error');
		var newobj = document.createElement('textarea');
		$(newobj).text(oldhtml);
		$(newobj).css('height',element.offsetHeight);
		$(newobj).css('width','100%');
		$(newobj).css('resize','none');
		$(newobj).addClass('form-control');
		$(newobj).attr('name',thele.attr('name'));
		newobj.onblur = function(){
			var form = table.data('bootstrapValidator');
			form.validate();
			var datas;
			if (form.isValid() == false) {
				element.innerHTML = oldhtml;
			}
			else {
				element.innerHTML = this.value;	
			}
			if (isStrEmpt($.trim(element.innerHTML)) && !isContains(thele.attr("class"),'notValidate')) {	
				$(element).addClass('not_Empty_td');
				showErr();
			}
		}
		element.innerHTML = '';
		var object;
		if (isContains(thele.attr("class"),'notValidate')) {
			object = $(element).append(newobj);
		}
		else {
			object = $(element).append(newdiv).children().append(newobj);
		}
		if (object.children().length == 1) {
			var form = table.data('bootstrapValidator');
			if (form != undefined) {
				table.data('bootstrapValidator').destroy();
				table.data('bootstrapValidator', null);
			}
			validata();			
		}
		newobj.focus();
	}
}
/**
 * 展示错误信息
 * 
 * @returns
 */
function showErr(){
	  jQuery(".not_Empty_td").hover(
	    function(e){
			    Mouse(e);
			    $(".showinfo").css({top:toppos,left:leftpos}).fadeIn(100);
	   		},
		function(){
			$(".showinfo").hide();
		}
	  )
}
var MouseEvent = function(e){
	 this.x = e.pageX;
	 this.y = e.pageY;
}

var Mouse = function(e){
	var kdheight =  jQuery(document).scrollTop();
	mouse = new MouseEvent(e);
	leftpos = mouse.x+10;
	toppos = mouse.y-kdheight+10; 
}

function myFunction() {
    return "是否刷新？刷新将重置未保存数据";
}